//
//  YHGameLayerMain.h
//  ThunderWarriors
//
//  Created by mac on 12-12-23.
//
//

#ifndef ThunderWarriors_YHGameLayerMain_h
#define ThunderWarriors_YHGameLayerMain_h
#include "YHLayer.h"
#include "YHGameLayerMap.h"
class YHGameLayerMain : public YHLayer {
public:
    
    YHGameLayerMain();
    virtual ~ YHGameLayerMain();
    virtual bool init();
    virtual void onEnter();
    virtual void update(float dt);
    
    bool loadClouds(); //加载云
    void generateRandomClouds(float t); //生成云
    void removeCloud(CCNode* nodeCloud);//移除云
    
    
    virtual void ccTouchesBegan(CCSet *pTouches,CCEvent *pEvent);
    virtual void ccTouchesMoved(CCSet *pTouches,CCEvent *pEvent);
    virtual void ccTouchesEnded(CCSet *pTouches,CCEvent *pEvent);
    
    bool _isTouchToMove;
    float xdelta;
    float ydelta;
    int _totalLives;
    int _totalScore;
    CCArray *_enemySprites;
    CCArray *_bulletSprites;
    CCLabelTTF * _lifeLabel;
    CCLabelTTF * _scoreLabel;
    CCLabelTTF * _gameEndLabel;
    CCMenu * _startGameMenu;
    bool _isGameStarted;
    bool _isEnemyColliable;
    bool _isPlayerColliable;
    CCAnimation *_playerBlowupAnimation;//玩家飞机爆炸动画
    CCAnimation *_enemyBlowuoAnimation;//敌机爆炸动画
    CCAction *_playerFlyAction;//飞机飞行动画
    
    
    CREATE_FUNC(YHGameLayerMain)
    CREATE_FUNC_LAYER_WITHID(YHGameLayerMain)
    DECLARE_CREATE_CLASS(YHGameLayerMain)
    
    //属性操作
    DECLARE_PROPERTY(YHGameLayerMain)
    
    //动态属性操作
    DECLARE_DYNAMIC_PROPERTY(YHGameLayerMain)
    
protected:
    void spawnEnemy();
    CCSprite* getAvailableEnemySprite();
    void resetEnemy(CCNode* pSender);
    void updatePlayerrShooting(float dt);
    void updateHUD(float dt);
    void bulletFinishedMoving(CCNode* pSender);
    CCSprite* getAvailableBulletSprite();
    void menuStartCallback(CCObject* pSender);
    void collisionDetection(float dt);
    CCRect reckOfSprite(CCSprite *sprite);
    CCAnimation * getAnimationByName(const char * animName,float delay,int num);
    void onRestartGame();
    CCSprite * getPlayerSprite();
    void resetPlayerPlane();
    void resetEnemyPlane();
    
private:
    CCSpriteBatchNode* m_spriteCloudsNear;
    CCSpriteBatchNode* m_spriteCloudsFar;
    
    YHGameLayerMap* m_gameLayerMap;
    

    
};

#endif
